from typing import Optional

from pydantic import BaseModel, Field
from sqlalchemy import Column, String, BigInteger, Text
from toollib.utils.now2timestamp_ import now2timestamp

from app.datatype import DeclBase, filter_fields
from app.initializer import g


class SessionMsg(DeclBase):
    __tablename__ = "session_msg"

    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="主键")
    #session_id
    session_id = Column(BigInteger, nullable=False, comment="会话ID")
    #消息内容
    content = Column(Text, nullable=False, comment="消息内容")
    created_at = Column(BigInteger, default=now2timestamp, comment="创建时间")
    updated_at = Column(BigInteger, default=now2timestamp, onupdate=now2timestamp, comment="更新时间")
    #删除状态
    is_deleted = Column(BigInteger, default=0, comment="删除状态，0未删除，1已删除")
    #消息关联内容
    content_relevancy = Column(Text, nullable=False, comment="消息关联内容")

class SessionMsgDetailMdl(BaseModel):
    id: str = Field(...)
    # #
    name: str = None

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )
class SessionMsgListGetMdl(BaseModel):
    session_id: int = Field(default = 1,title="会话id", description="会话ID")

# 获取聊天记录
class SessionMsgListMdl(BaseModel):
    id: int = Field(default = 1, title="聊天记录ID", description="聊天记录ID")
    session_id: int = Field(default = 1,title="会话id", description="会话ID")
    content: Optional[str]  = Field(default = "内容", title="消息内容", description="消息内容")
    content_relevancy: Optional[str]  = Field(default = "关联内容", title="关联内容", description="关联内容")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

# 添加聊天记录
class SessionMsgCreateMdl(BaseModel):
    session_id: int = Field(default=1, description="会话ID")
    content: str = Field(default="", description="消息内容")
    #消息关联内容
    content_relevancy: str = Field(default="", description="消息关联内容")
    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

#修改了聊天记录
class SessionMsgUpdateMdl(BaseModel):
    id: int = Field(..., description="聊天记录ID")
    content: str = Field(..., description="消息内容")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

#删除聊天记录
class SessionMsgDeleteMdl(BaseModel):
    id: int = Field(..., description="聊天记录ID")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )